{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "isolated-heather",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "Azure Quantum workspace not fully specified. Please specify either a valid resource ID or a valid combination of subscription ID, resource group name, and workspace name.",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-1-adf407d4b43a>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      8\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      9\u001b[0m \u001b[1;31m# Workspace information\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 10\u001b[1;33m workspace = Workspace(\n\u001b[0m\u001b[0;32m     11\u001b[0m     \u001b[0msubscription_id\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"\"\u001b[0m\u001b[1;33m,\u001b[0m  \u001b[1;31m# Add your subscription_id\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     12\u001b[0m     \u001b[0mresource_group\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"\"\u001b[0m\u001b[1;33m,\u001b[0m   \u001b[1;31m# Add your resource_group\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\azure\\quantum\\workspace.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, subscription_id, resource_group, name, storage, resource_id, location)\u001b[0m\n\u001b[0;32m    287\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    288\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0msubscription_id\u001b[0m \u001b[1;32mor\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mresource_group\u001b[0m \u001b[1;32mor\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 289\u001b[1;33m             raise ValueError(\n\u001b[0m\u001b[0;32m    290\u001b[0m                 \u001b[1;34m\"Azure Quantum workspace not fully specified. Please specify either a valid resource ID \"\u001b[0m \u001b[1;33m+\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    291\u001b[0m                 \"or a valid combination of subscription ID, resource group name, and workspace name.\")\n",
      "\u001b[1;31mValueError\u001b[0m: Azure Quantum workspace not fully specified. Please specify either a valid resource ID or a valid combination of subscription ID, resource group name, and workspace name."
     ]
    }
   ],
   "source": [
    "# Copyright (c) Microsoft Corporation.\n",
    "# Licensed under the MIT License.\n",
    "\n",
    "from azure.quantum import Workspace\n",
    "from azure.quantum.optimization import Problem, ProblemType, Term\n",
    "from azure.quantum.optimization.oneqbit import TabuSearch, PticmSolver, PathRelinkingSolver\n",
    "import time\n",
    "\n",
    "# Workspace information\n",
    "workspace = Workspace(\n",
    "    subscription_id = \"\",  # Add your subscription_id\n",
    "    resource_group = \"\",   # Add your resource_group\n",
    "    name = \"\",             # Add your workspace name\n",
    "    location = \"\"          # Add your workspace location (for example, \"westus\")\n",
    ")\n",
    "\n",
    "# Login\n",
    "workspace.login()\n",
    "\n",
    "# Define the problem\n",
    "problem = Problem(name=\"My First 1QBit Problem\", problem_type=ProblemType.ising)\n",
    "\n",
    "problem.add_terms([\n",
    "    Term(w=-9, indices=[0]),\n",
    "    Term(w=-3, indices=[1,0]),\n",
    "    Term(w=5, indices=[2,0]),\n",
    "    Term(w=9, indices=[2,1]),\n",
    "    Term(w=2, indices=[3,0]),\n",
    "    Term(w=-4, indices=[3,1]),\n",
    "    Term(w=4, indices=[3,2])\n",
    "])\n",
    "\n",
    "# Create 1QBit solvers\n",
    "print('instantiate solvers...')\n",
    "solvers = [\n",
    "    TabuSearch(workspace, improvement_cutoff=10),\n",
    "    PticmSolver(workspace, num_sweeps_per_run=99),\n",
    "    PathRelinkingSolver(workspace, distance_scale=0.44),\n",
    "]\n",
    "\n",
    "# Submit the problem to each solver\n",
    "print('submit jobs...')\n",
    "jobs = [solver.submit(problem) for solver in solvers]\n",
    "\n",
    "# Solve the problem\n",
    "for job in jobs:\n",
    "    while job.details.status != 'Succeeded' and job.details.status != 'Failed':\n",
    "        job.refresh()\n",
    "        print(f'Job {job.id} ({job.details.target}) state is {job.details.status}')\n",
    "        time.sleep(1)\n",
    "\n",
    "print('All jobs complete!')\n",
    "for job in jobs:\n",
    "    results = job.get_results()\n",
    "    print('{0}: {1}'.format(job.details.target, results))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "foreign-living",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
